<template>
  <div id="reviseress">
    <van-col span="24">
      <van-nav-bar title="修改地址" left-arrow @click-left="onClickLeft" />
    </van-col>
    <van-row>
      <van-col span="24">
        <van-form>
          <van-field v-model="DataList.name" name="姓名" label="姓名" placeholder="用户名" />
          <van-field v-model="DataList.tel" name="电话" label="电话" placeholder="用户名" />
          <van-field v-model="DataList.name" name="地区" label="地区" />
          <van-field v-model="DataList.addressDetail" name="详细地址" label="详细地址" placeholder="用户名" />
          <van-cell center title="设置默认收货地址">
            <template #right-icon>
              <van-switch v-model="DataList.isDefault" size="24" />
            </template>
          </van-cell>
          <div style="margin: 16px;">
            <van-button round block type="danger" @click="onModify">保存</van-button>
          </div>
          <div style="margin: 16px;">
            <van-button round block @click="onDelRess">删除</van-button>
          </div>
        </van-form>
      </van-col>
    </van-row>
  </div>
</template>
<script>
import { Toast } from 'vant'
export default {
  name,
  data() {
    return {
      checked: '',
      DataList: ''
    }
  },
  mounted() {
    this.DataList = this.$route.query
    console.log(this.DataList)
  },
  methods: {
    onClickLeft() {
      this.$router.back()
    },
    // 修改 保存
    onModify() {
      let data = {
        name: this.DataList.name, //收货人姓名
        tel: this.DataList.tel, //电话
        province: this.DataList.province, //省
        city: this.DataList.city, //市
        county: this.DataList.county, //区
        addressDetail: this.DataList.addressDetail, //详细地址
        isDefault: this.DataList.isDefault, //是否默认
        id: this.DataList.id //修改地址时传当前地址id，添加地址时不用传
      }
      this.$post('address/save', data).then(result => {
        console.log(result)
        Toast.success('修改成功')
        this.$router.push('/ress')
      })
    },
    onDelRess() {
      console.log(this.DataList.id)
      this.$post('address/delete', { id: this.DataList.id }).then(result => {
        console.log(result)
        Toast.loading({
          message: '加载中...',
          forbidClick: true
        })
        setTimeout(() => {
          Toast.success('删除成功')
          this.$router.back()
        }, 2000)
      })
    }
  }
}
</script>
<style lang="less" scoped>
.van-row {
  padding: 0.15rem;
}
</style>
